package com.example.transactionhintassistant.controller;

import com.example.transactionhintassistant.pojo.dto.memo.AddMemoDto;
import com.example.transactionhintassistant.pojo.dto.memo.ChangeMemoDto;
import com.example.transactionhintassistant.service.MemosService;
import com.example.transactionhintassistant.utils.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/memos")
@Tag(name = "4.备忘录模块")
public class MemosController {
    @Autowired
    private MemosService memosService;

    @GetMapping("/list")
    @Operation(summary = "获取个人备忘录", security = {@SecurityRequirement(name = "Authorization")})
    public Result<Object> getMyMemos()
    {
        return memosService.getMyMemos();
    }

    @DeleteMapping("/delete/{id}")
    @Operation(summary = "根据id删除个人备忘录")
    public Result<Object> deleteMyMemoById(@PathVariable int id)
    {
        return memosService.deleteMemoById(id);
    }

    @PutMapping("/change")
    @Operation(summary = "修改个人备忘录")
    public Result<Object> changeMyMemo(@RequestBody @Validated ChangeMemoDto changeMemoDto)
    {
         return memosService.changeMyMemo(changeMemoDto);
    }

    @PostMapping("/add")
    @Operation(summary = "增加备忘录", security = {@SecurityRequirement(name = "Authorization")})
    public Result<Object> addMemo(@RequestBody @Validated AddMemoDto addMemoDto)
    {
        return memosService.addMemo(addMemoDto);
    }

    @GetMapping("/detail/{id}")
    @Operation(summary = "查看备忘录详情", security = {@SecurityRequirement(name = "Authorization")})
    public Result<Object> getMemoDetailById(@PathVariable int id)
    {
        return memosService.getMemoDetailById(id);
    }
}
